/*
* Copyright (C) 2012 Manuel Pérez
*
* This file is part of OpenSudoku.
*
* OpenSudoku is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* OpenSudoku is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenSudoku. If not, see <http://www.gnu.org/licenses/>.
*
*/
package modeloa;

import java.awt.Dimension;
import java.sql.SQLException;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import dBasea.Kontsultak;

public class PerituModeloa extends AbstractTableModel {

	private static final long serialVersionUID = -6594731089903319422L;
	String[] columnNames = { "NAN", "Izena", "Abizenak", "Telefonoa", "Hiria" };
	List<Peritu> perituak;
	int x;
	String i;
	private Kontsultak konts = new Kontsultak();

	public void init() {
		try {
			perituak = konts.listatuPerituak();
		} catch (SQLException e) {

			e.printStackTrace();
		}
	}

	public void init2(int i, String text) {
		try {
			perituak = konts.bilatuPerituak(i, text);
		} catch (SQLException ex) {

			ex.printStackTrace();
		}

	}

	public int getColumnCount() {
		return columnNames.length;
	}

	public int getRowCount() {
		return perituak.size();
	}

	public String getColumnName(int col) {
		return columnNames[col];
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		switch (columnIndex) {
		case 0:
			return perituak.get(rowIndex).getIdPeritua();
		case 1:
			return perituak.get(rowIndex).getIzena();
		case 2:
			return perituak.get(rowIndex).getAbizenak();
		case 3:
			return perituak.get(rowIndex).getTelefonoa();
		case 4:
			return perituak.get(rowIndex).getHiria();

		default:
			return null;
		}
	}

	public boolean isCellEditable(int row, int col) {
		return false;
	}

	public Peritu getFila(int index) {
		return perituak.get(index);
	}

	public void setPreferredScrollableViewportSize(Dimension dimension) {
		this.setPreferredScrollableViewportSize(dimension);
	}
}
